// *************************************
// * Creator:SunnyPaine
// * DateTime:2024/08/09 09:08:18
// * Description:<Description>
// * CopyRight:
// * ***********************************

using System;

namespace SunnyPaine.Autofac.Extension.Mvvm.Commands
{
    /// <summary>
    /// 当对命令调用Execute和CanExecute逻辑时，调用无参数委托的命令。
    /// </summary>
    public class RelayCommand : BaseCommand<object>
    {
        /// <summary>
        /// 使用默认参数创建 <see cref="RelayCommand"/> 的实例。
        /// </summary>
        /// <param name="executeMethod">命令方法。</param>
        /// <param name="canExecuteMethod">是否克执行命令的校验方法。</param>
        public RelayCommand(Action executeMethod, Func<bool> canExecuteMethod = null)
        {
            if (executeMethod != null)
            {
                base.executeMethod = o => executeMethod();
            }

            if (canExecuteMethod != null)
            {
                this.canExecuteMethod = o => canExecuteMethod();
            }
        }
    }

    /// <summary>
    /// 当对命令调用Execute和CanExecute逻辑时，调用有参数委托的命令。
    /// </summary>
    public class RelayCommand<T> : BaseCommand<T>
    {
        /// <summary>
        /// 使用默认参数创建 <see cref="RelayCommand"/> 的实例。
        /// </summary>
        /// <param name="executeMethod">命令方法。</param>
        /// <param name="canExecuteMethod">是否克执行命令的校验方法。</param>
        public RelayCommand(Action<T> executeMethod, Func<T, bool> canExecuteMethod = null)
        {
            base.executeMethod = executeMethod;
            base.canExecuteMethod = canExecuteMethod;
        }
    }
}